<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>首页</title>
    <style>

    </style>
</head>
<body>

<h3 id="usernametitle"></h3>

<br>

<button id="writebtn">写博客</button>

<table id="tab">

<tr>
    <td>题目</td>
    <td>文章摘要</td>
</tr>

</table>

</body>

<script src="http://cdn.static.runoob.com/libs/jquery/1.10.2/jquery.min.js">
</script>

<script>

    var table = $("#tab");
    var uid;
    var writebtn = $("#writebtn")

    checkCookie();

    getArticalList();

    function getCookie(cname) {
        var name = cname + "=";
        var ca = document.cookie.split(';');
        for (var i = 0; i < ca.length; i++) {
            var c = ca[i].trim();
            if (c.indexOf(name) == 0) {
                return c.substring(name.length, c.length);
            }
        }
        return "";
    }

    function checkCookie() {
        var user = getCookie("name");
        uid = getCookie("userId");


        $("#usernametitle").text("你好:" + user);
    }

    function getArticalList() {
        $.ajax({
            url:"json/selectArticalList",
            type:"get",
            data:{
                page: 1,
                num: 20,
                userId: uid,
                 },
            success:function (result) {

                for (var i in result.blogs) {
                    //利用for循环给table添加行
                    var itemContent = result.blogs[i];

                    var item = $("<tr><td>" + itemContent.title + "</td>"
                            + "<td>"+ itemContent.des  +"</td>"+"</tr>");

                    table.append(item);

                }
            }
        })
    }

    writebtn.click(function () {
       window.location.href = "http://localhost:8080/writeblog";
    });

</script>
</html>